package com.wlyuan.open.domain;

import com.wlyuan.core.marker.NamedValue;
import com.wlyuan.core.marker.NamedValues;
import lombok.RequiredArgsConstructor;
import lombok.ToString;

import java.util.Map;

/**
 * @author
 * 推送业务类型
 */
@RequiredArgsConstructor
@ToString
public class PushBusinessType implements NamedValue<Integer> {
    private final Integer value;
    private final String name;
    private final String desc;

    public static final PushBusinessType ORDER_SIGNED = new PushBusinessType(1,"OrderSigned","订单签收");
    public static final PushBusinessType TRACK_SET_OUT = new PushBusinessType(2,"setOut","发出出发短信");
    public static final PushBusinessType TRACK_REAL_FROM = new PushBusinessType(3,"realFrom","实际出发");
    public static final PushBusinessType TRACK_PRE_REACH = new PushBusinessType(4,"preReach","发送预到达短信（签收验证短信）");
    public static final PushBusinessType TRACK_REACH = new PushBusinessType(5,"reach","实际到达");
    public static final PushBusinessType TRACK_LOW_BATTERY = new PushBusinessType(6,"lowBattery","低电量");
    public static final PushBusinessType TRACK_LONG_STAY = new PushBusinessType(7,"longStay","超长停留");
    public static final PushBusinessType CARRIER_AGREED = new PushBusinessType(8,"CarrierAgreed","生成有效的承运商");
    public static final PushBusinessType WAYBILL_PICK_COVENANT = new PushBusinessType(9,"WaybillPickCovenant","提货预约");
    public static final PushBusinessType ORDER_RECEIPT = new PushBusinessType(10,"OrderReceipted","订单回单");
    public static final PushBusinessType ORDER_SCORED = new PushBusinessType(11,"OrderScored","订单评分");

    private static final Map<Integer,PushBusinessType> MAP = new NamedValues<Integer, PushBusinessType>(PushBusinessType.class);

    @Override
    public String getName() {
        return this.name;
    }

    @Override
    public Integer getValue() {
        return this.value;
    }

    public static PushBusinessType fromValue(Integer value){
        if(null== value){
            return null;
        }
        return MAP.get(value);
    }

    public static PushBusinessType fromName(String name){
        if(null == name){
            return null;
        }
        for(Map.Entry entry: MAP.entrySet()){
            PushBusinessType value  =(PushBusinessType) entry.getValue();
            if(value.getName().equals(name)){
                return value;
            }
        }
        return null;
    }
}
